const App = {
	props: ['obj'],
	template: '<div>obj.name</div>'
}

const routes = [
  { path: '/app', component: App }
]
 
// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const routerVue = new VueRouter({
  routes // （缩写）相当于 routes: routes
})

var vueApp = new Vue({
	el: '#main',
	router: routerVue,
	data : {
		title: '我的好友',
		message: '',
		icon_show: false,
		default: true,
		requestList:[],
		responseList:[],
		groupList: [],
		searchList: [],
		friendList: [],
	},
	mounted: function() {
		this.init();
	},
	methods: {
		init: function() {
			var that = this;
			util.tokenPost("https://www.maksdu.com/app/communicate/get",null,function(result){	
                if(result.login_status) {
	                var len = 0;
	                var infoText = null;
    	            var i = 0;
        	        var requestList = new Array();
	                for(var key in result.value.friends)  {
	                    i++;
	                    if(i < Object.getOwnPropertyNames(result.value.friends).length){
	                        infoText = result.value.friends[key];
	                        if(infoText.userId == util.local('userid')) {
	                        	continue;
	                        }

	                        requestList.push(infoText);
	                        if(infoText.status == "REQ") {
	                        	len++;
	                        } else if(infoText.status == "LINK") {
	                        	var friend = {
	                        		avator: infoText.avator,
	                        		requestDate: new Date(infoText.requestDate).Format('HH:mm'),
	                        		nickName: infoText.nickName,
	                        		message: ''
	                        	}
	                        	that.friendList.push(friend);
	                        } else {
	                        	that.responseList.push(infoText);
	                        }
	                    } else {
	                        infoText = result.value.friends[key];
	                        requestList.push(infoText);
	                        if(infoText.status == "REQ") {
	                        	len++;
	                        } else if(infoText.status == "LINK") {
	                        	var friend = {
	                        		avator: infoText.avator,
	                        		requestDate: new Date(infoText.requestDate).Format('HH:mm'),
	                        		nickName: infoText.nickName,
	                        		message: ''
	                        	}
	                        	that.friendList.push(friend);
	                        } else {
	                        	that.responseList.push(infoText);
	                        }
	                    }
	                };
					util.localSet('control',requestList);
	                if(infoText) {
						var date = new Date(infoText.requestDate).Format('HH:mm');
						var msg = infoText.username;
						var group = {
							id: infoText.userId,
							headerUrl: 'images/yzxx.png',
							name: '验证消息',
							message: '您有'+len+'条验证信息未处理',
							date: date,
							number: len,
							type: 'control'
						}
						that.groupList.push(group);
					}
				} else {
					window.location.replace("https://www.maksdu.com/login/");
				}
			});
			
		},
		reset: function(){
			this.icon_show = false
		},
		iconShow: function() {
			if(!this.icon_show)
				this.icon_show = true
			else
				this.icon_show = false
		},
		goto: function(url,e) {
			window.location.replace(url);
		}
	}
})